home *** CD-ROM | disk | FTP | other *** search
/ SoundMaker 2003 (Professional Edition) / SoundMaker 2003 - Professional Edition.iso / midi tool / midioxse.exe / DATA.1 / VBSPoll.vbs < prev    next >
Text File  |  1999-11-26  |  4KB  |  134 lines

  1. ' MIDIOX Test - Polling Example
  2. ' Copyright (c) 2000 by Jamie O'Connell
  3. '
  4. ' This script is an example of using VBScript with MIDI-OX
  5.  
  6. option explicit
  7.  
  8. dim mox
  9. dim str, strWrk, strSysEx
  10. dim n, ii, nInst
  11. dim bGo
  12. dim chan, stat, dat1, dat2
  13. dim msg, msgstr
  14. dim A
  15.  
  16. ' Wsh version
  17. Str = Wscript.Name & " ver. " & Wscript.Version
  18. MsgBox str
  19.  
  20. ' Create object
  21. Set mox = WScript.CreateObject("MoxKart.MoxWire.1")  
  22.  
  23. str = "MIDI-OX"
  24. n = mox.NumberInstances
  25. If n > 0 Then
  26.   str = str & ":" & CStr( n )
  27. Else
  28.   MsgBox "No Instances"
  29. End If
  30.  
  31. str = str & " "
  32. str = str & mox.GetAppVersion 
  33.  
  34. MsgBox str
  35.  
  36. If n > 0 then
  37.   nInst = 1
  38.   If n > 1 then
  39.      nInst = InputBox( "Attach to which instance? (1 to " & n & ")", "Attach", "1" )
  40.   End If
  41.   If mox.AttachInstance( nInst ) = 1 Then     
  42.      MsgBox "Attached Instance: " & nInst
  43.   Else
  44.      MsgBox "Could not Attach Instance: " & nInst
  45.   End If
  46. ElseIf vbYes = MsgBox( "Launch MIDI-OX?", vbYesNo + vbQuestion, "Launch"  ) Then
  47.   If mox.LaunchInstance = 1 Then
  48.      nInst = 1
  49.      If mox.AttachInstance( nInst ) = 1 Then    
  50.         MsgBox "Launched and Attached Instance: " & nInst
  51.      Else
  52.         MsgBox "Launched but could not Attach Instance: " & nInst   
  53.      End If
  54.   Else
  55.      MsgBox "Launch MIDI-OX Failed"
  56.   End If
  57.   n = mox.NumberInstances
  58. End if
  59.  
  60.  
  61. ' *** Try out our MIDI Input loop
  62. mox.FireMidiInput = 0
  63.  
  64. str = "Enter MIDI Input Loop?" & vbCrLf & "(Exit Script from MIDI-OX)"
  65. If mox.IsAttached = 1 And vbYes = MsgBox( str, vbYesNo + vbQuestion, "MIDI Notes"  ) Then
  66.    If vbYes = MsgBox( "Divert MIDI Input?", vbYesNo + vbQuestion, "MIDI Notes"  ) Then
  67.       mox.DivertMidiInput = 1
  68.    Else
  69.       mox.DivertMidiInput = 0
  70.    End If
  71.  
  72.    Do While mox.ShouldExitScript = 0
  73.       ' First way of getting input: try raw Input
  74.       msg = mox.GetMidiInputRaw()    
  75.       If msg <> 0 Then
  76.          stat = msg And &h000000F0
  77.          chan = msg And &h0000000F
  78.          If mox.DivertMidiInput = 0 And (stat = &h90 Or stat = &h80) Then
  79.             chan = chan + 1
  80.             If chan > 15 Then
  81.                chan = 0
  82.             End If
  83.          End If
  84.  
  85.      If (stat = &hF0) Then ' SysEx, must ask for SysEx string message
  86.         strSysEx = mox.GetSysExInput()
  87.             mox.SendSysExString strSysEx
  88.          Else
  89.             msg  = msg \ 256     ' pull off stat
  90.             dat1 = msg And &h0000007F
  91.             msg  = msg \ 256
  92.             dat2 = msg And &h0000007F        
  93.             mox.OutputMidiMsg stat + chan, dat1, dat2                   
  94.          End If
  95.       End If
  96.  
  97.       ' Second way: Now try the string format
  98.       msgStr = mox.GetMidiInput()    
  99.       If msgStr <> "" Then
  100.          A = Split( msgStr, ",", -1, vbTextCompare )
  101.          stat = Int(A(1))
  102.          chan = Int(A(2))
  103.          If mox.DivertMidiInput = 0 And (stat = &h90 Or stat = &h80) Then
  104.             chan = chan + 1
  105.             If chan > 15 Then
  106.                chan = 0
  107.             End If
  108.          End If
  109.  
  110.          If (stat = &hF0) Then ' SysEx, must ask for SysEx string message
  111.         strSysEx = mox.GetSysExInput()
  112.             mox.SendSysExString strSysEx 
  113.          Else
  114.             dat1 = Int(A(3))
  115.             dat2 = Int(A(4))
  116.             mox.OutputMidiMsg stat + chan, dat1, dat2                   
  117.          End If
  118.       End If
  119.    Loop
  120.  
  121.    mox.DivertMidiInput = 0
  122. End If
  123.  
  124. MsgBox "End Demo"
  125.  
  126. Set str      = nothing
  127. Set strWrk   = nothing
  128. Set mox      = nothing
  129. Set strSysEx = nothing
  130.  
  131. ' Exit Point
  132. '------------------------------------------
  133.  
  134.